<script setup lang="ts">
defineProps({
    // 整个盒子的宽度
    width: {
        type: String,
        default: '14em'
    },
    // 整个盒子的高度
    height: {
        type: String,
        default: '10em'
    },
    // 水平位置（left值）
    left: {
        type: String,
        default: '0'
    },
    // 垂直位置（top值）
    top: {
        type: String,
        default: '0'
    }
})
</script>

<template>
    <div class="capybara-loader" :style="{ width, height, left, top }">
        <div class="capybara">
            <div class="capybara-head">
                <div class="capybara-ear">
                    <div class="capybara-ear-inner"></div>
                </div>
                <div class="capybara-ear"></div>
                <div class="capybara-mouth">
                    <div class="capybara-lip"></div>
                    <div class="capybara-lip"></div>
                </div>
                <div class="capybara-eye"></div>
                <div class="capybara-eye"></div>
            </div>
            <div class="capybara-leg"></div>
            <div class="capybara-leg-2"></div>
            <div class="capybara-leg-2"></div>
            <div class="capybara-body"></div>
        </div>
        <div class="loader">
            <div class="loader-line"></div>
        </div>
    </div>
</template>

<style scoped>
.capybara-loader {
    position: relative;
    z-index: 1;
    --color: rgb(204, 125, 45);
    --color2: rgb(83, 56, 28);
    transform: scale(0.75);
}
.capybara {
    width: 100%;
    height: 7.5em;
    position: relative;
    z-index: 1;
}
.loader {
    width: 100%;
    height: 2.5em;
    position: relative;
    z-index: 1;
    overflow: hidden;
}
.capybara-body {
    width: 85%;
    height: 100%;
    background: linear-gradient(var(--color), 90%, var(--color2));
    border-radius: 45%;
    position: relative;
    z-index: 1;
    animation: move-body 1s linear infinite;
}
.capybara-head {
    width: 7.5em;
    height: 7em;
    bottom: 0;
    right: 0;
    position: absolute;
    background-color: var(--color);
    z-index: 3;
    border-radius: 3.5em;
    box-shadow: -1em 0 var(--color2);
    animation: move-body 1s linear infinite;
}
.capybara-ear {
    width: 2em;
    height: 2em;
    background: linear-gradient(-45deg, var(--color), 90%, var(--color2));
    top: 0;
    left: 0;
    border-radius: 100%;
    position: absolute;
    overflow: hidden;
    z-index: 3;
}
.capybara-ear:nth-child(2) {
    left: 5em;
    background: linear-gradient(25deg, var(--color), 90%, var(--color2));
}
.capybara-ear-inner {
    width: 100%;
    height: 1em;
    background-color: var(--color2);
    bottom: 0;
    left: 0.5em;
    border-radius: 100%;
    position: absolute;
    transform: rotate(-45deg);
}
.capybara-mouth {
    width: 3.5em;
    height: 2em;
    background-color: var(--color2);
    position: absolute;
    bottom: 0;
    left: 2.5em;
    border-radius: 50%;
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 0.5em;
}
.capybara-lip {
    width: 0.25em;
    height: 0.75em;
    border-radius: 100%;
    transform: rotate(-45deg);
    background-color: var(--color);
}
.capybara-lip:nth-child(2) {
    transform: rotate(45deg);
}
.capybara-eye {
    width: 2em;
    height: 0.5em;
    background-color: var(--color2);
    position: absolute;
    bottom: 3.5em;
    left: 1.5em;
    border-radius: 5em;
    transform: rotate(45deg);
}
.capybara-eye:nth-child(4) {
    transform: rotate(-45deg);
    left: 5.5em;
    width: 1.75em;
}
.capybara-leg {
    width: 6em;
    height: 5em;
    bottom: 0;
    left: 0;
    position: absolute;
    background: linear-gradient(var(--color), 95%, var(--color2));
    z-index: 2;
    border-radius: 2em;
    animation: move-body 1s linear infinite;
}
.capybara-leg-2 {
    width: 1.75em;
    height: 3em;
    bottom: 0;
    left: 3.25em;
    position: absolute;
    background: linear-gradient(var(--color), 80%, var(--color2));
    z-index: 2;
    border-radius: 0.75em;
    box-shadow: inset 0 -0.5em var(--color2);
    animation: move-leg 1s linear infinite;
}
.capybara-leg-2:nth-child(3) {
    width: 1.25em;
    left: 0.5em;
    height: 2em;
    animation: move-leg-2 1s linear infinite 0.075s;
}

@keyframes move-leg {
    0% {
        transform: rotate(-45deg) translateX(-5%);
    }
    50% {
        transform: rotate(45deg) translateX(5%);
    }
    100% {
        transform: rotate(-45deg) translateX(-5%);
    }
}

@keyframes move-leg-2 {
    0% {
        transform: rotate(45deg);
    }
    50% {
        transform: rotate(-45deg);
    }
    100% {
        transform: rotate(45deg);
    }
}

@keyframes move-body {
    0% {
        transform: translateX(0);
    }
    50% {
        transform: translateX(2%);
    }
    100% {
        transform: translateX(0);
    }
}

.loader-line {
    width: 50em;
    height: 0.5em;
    border-top: 0.5em dashed var(--color2);
    animation: move-line 10s linear infinite;
}

@keyframes move-line {
    0% {
        transform: translateX(0);
        opacity: 0;
    }
    5% {
        opacity: 100%;
    }
    95% {
        opacity: 100%;
    }
    100% {
        opacity: 0;
        transform: translateX(-70%);
    }
}
</style>
